<template>
  <div>
    <div class="root">
      <div class="item">
        <input
          type="checkbox"
          @change="selectAllOrCancel"
          :checked="finsh === total"
        />
      </div>
      <div class="item">
        <span>已完成{{ finsh }}</span> / <span>全部{{ total }}</span>
      </div>
      <div class="item">
        <button @click="deleteFinish">清除已完成列表</button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: ["todoList"],
  data() {
    return {
      arr: [],
    };
  },
  methods: {
    selectAllOrCancel(e) {
      console.log("selectAllOrCancel");
      this.$emit('selectAll',e.target.checked)
    },

    deleteFinish(){
      this.$emit('deleteFinish')
    }
  },
  computed: {
    finsh: {
      get() {
        return this.todoList.reduce(
          (resp, todo) => (resp += todo.done ? 1 : 0),
          0
        );
      },
    },
    total() {
      return this.todoList.length;
    },
  },
};
</script>

<style lang="less" scoped>

  .root{
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    .item:nth-last-child(1){
      margin-left: auto;
    }
  }
</style>
